package com.hy.controller;

import com.hy.Vo.PurchaseApplyDeptUserVo;
import com.hy.bean.PurchaseApply;
import com.hy.bean.RespBean;
import com.hy.service.PurchaseApplyService;
import com.hy.service.impl.PurchaseApplyServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (PurchaseApply)表控制层
 *
 * @author makejava
 * @since 2024-04-29 14:47:14
 */
@RestController
@RequestMapping("purchaseApply")
public class PurchaseApplyController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    /**
     * 服务对象
     */

    private PurchaseApplyService purchaseApplyService = new PurchaseApplyServiceImpl();

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<PurchaseApply> queryById(@PathVariable("id") int id) {
        return ResponseEntity.ok(this.purchaseApplyService.queryById(id));
    }

    @GetMapping("paId/{id}")
    public PurchaseApply queryByPaId(@PathVariable("id") Integer id){
        logger.debug("queryByPaId{}",id);
        return purchaseApplyService.queryByPaId(id);
    }

    @GetMapping("getPurchaseApply/{deptName}/{username}")
    public List<PurchaseApplyDeptUserVo> queryAll(@PathVariable("deptName") String deptName,@PathVariable("username") String username){
        return purchaseApplyService.queryAll(deptName,username);
    }

    /**
     * 新增数据
     *
     * @param purchaseApply 实体
     * @return 新增结果
     */
    @PostMapping("add")
    public RespBean add(@RequestBody PurchaseApply purchaseApply) {
        logger.debug("add{}",purchaseApply);
        return this.purchaseApplyService.insert(purchaseApply);
    }

    /**
     * 编辑数据
     *
     * @param purchaseApply 实体
     * @return 编辑结果
     */
    @PutMapping("update")
    public RespBean edit(@RequestBody PurchaseApply purchaseApply) {
        return purchaseApplyService.update(purchaseApply);
    }

    @PutMapping("updateStatus/{id}/{status}")
    public RespBean updateStatusById(@PathVariable("id") Integer id,@PathVariable("status") Integer status){
        return purchaseApplyService.updateStatus(id,status);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("delete/{id}")
    public RespBean deleteById(@PathVariable("id") Integer id) {
        return purchaseApplyService.deleteById(id);
    }

}

